package com.example.employee.service.impl;

import com.example.common.context.BaseContext;
import com.example.employee.domain.dto.AdvertiseDTO;
import com.example.employee.domain.po.Advertisement;
import com.example.employee.domain.vo.AdvertiseVO;
import com.example.employee.mapper.AdvertisementMapper;
import com.example.employee.service.AdvertisementService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class AdvertisementServiceImpl implements AdvertisementService {
    private final AdvertisementMapper advertisementMapper;

    /**
     * 获取广告信息
     *
     * @param position
     * @return
     */
    @Override
    public List<AdvertiseVO> getAdvertise(Integer position) {
        List<AdvertiseVO> list = advertisementMapper.selectAdvertise(position);
        return list;
    }

    /**
     * 添加广告信息
     *
     * @param advertiseDTO
     */
    @Override
    public void addAdvertise(AdvertiseDTO advertiseDTO) {
        Advertisement advertisement = new Advertisement();
        BeanUtils.copyProperties(advertiseDTO, advertisement);
        // 创建时间,修改时间
        advertisement.setCreatedAt(LocalDateTime.now());
        advertisement.setUpdatedAt(LocalDateTime.now());
        // 创建人
        advertisement.setCreater(BaseContext.getCurrentId());
        advertisement.setUpdater(BaseContext.getCurrentId());
        advertisementMapper.insert(advertisement);

    }
}
